using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using QuickReportMaui.Model;

namespace QuickReportMaui.Views;

public partial class Summary : ContentPage
{
    public string Position { get; set; }
    public string Quantity { get; set; }

    public string Description { get; set; }
    public string Data { get; set; }
    public Summary()
    {
        Quantity = FeatureData.Quantity.ToString();
        Description = FeatureData.Description.ToString();
        Data = FeatureData.Data.ToString();
        Position = GetPosition();
        InitializeComponent();
        this.BindingContext = this;
    }
    private string GetPosition()
    {
        var point = FeatureData.Feature.Geometry as MapPoint;
        return $"X:{point.X},Y:{point.Y}";
    }

    private async void Submit(object sender, EventArgs e)
    {
        FeatureData.Feature.SetAttributeValue("Quantity", FeatureData.Quantity);
        FeatureData.Feature.SetAttributeValue("Description", FeatureData.Description);
        FeatureData.Feature.SetAttributeValue("DataTime", FeatureData.Data);
        var arcgisFeature = (ArcGISFeature)FeatureData.Feature;
        if (FeatureData.Photo != null)
        {
            await arcgisFeature.AddAttachmentAsync("ͼƬ", FeatureData.ContentType, FeatureData.Photo.ToArray());
        }
        await FeatureData.ServiceFeatureTable.AddFeatureAsync(FeatureData.Feature);
        await FeatureData.ServiceFeatureTable.ApplyEditsAsync();

    }
}